package control;

import java.util.LinkedList;
import java.util.Observable;
import java.util.Queue;

import javax.swing.Icon;

import view.StatusMessage;
import view.tables.IconizedInterface;

public class MessageHandler extends Observable {
	private Queue<IconizedInterface> queue = new LinkedList<IconizedInterface>();
	private static MessageHandler instance;
	
	private MessageHandler(){
		
	}
	
	public static MessageHandler getInstance(){
		if(instance == null){
			instance = new MessageHandler();
		}
		return instance;
	}
	
	public static void putMessage(IconizedInterface msg){
		instance.queue.offer(msg);
		instance.setChanged();
		instance.notifyObservers();
	}
	
	public static void putMessage(String text){
		putMessage(new StatusMessage(text));
	}
	
	public static void putMessage(String text, Icon icon){
		putMessage(new StatusMessage(text, icon));
	}
	
	public static IconizedInterface getMessage(){
		return instance.queue.poll();
	}
}
